package com.yh.manage.cms.controller;

import com.lxw.api.cms.CmsPreviewControllerApi;
import com.lxw.framework.web.BaseController;
import com.yh.manage.cms.service.CmsPageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@Slf4j
public class CmsPreviewController extends BaseController implements CmsPreviewControllerApi {

    @Autowired
    private CmsPageService cmsPageService;

    @Override
    @GetMapping("/cms/preview/{pageId}")
    public void preview(@PathVariable String pageId) {

        String htmlContent = cmsPageService.getHtmlPageById(pageId);
        try {
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().write(htmlContent);
        } catch (IOException e) {
            log.error(e.getMessage());
            e.printStackTrace();
        }
    }
}
